package org.dromara.system.controller.system;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.SysUserPurseBo;
import org.dromara.system.domain.vo.SysUserPurseVo;
import org.dromara.system.service.ISysUserPurseService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【请填写功能名称】
 *
 * @author Lion Li
 * @date 2025-07-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/userPurse")
public class SysUserPurseController extends BaseController {

    private final ISysUserPurseService sysUserPurseService;

    /**
     * 查询用户钱包列表
     */
//    @SaCheckPermission("system:userPurse:list")
    @GetMapping("/list")
    public TableDataInfo<SysUserPurseVo> list(SysUserPurseBo bo, PageQuery pageQuery) {
        return sysUserPurseService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出用户钱包列表
     */
//    @SaCheckPermission("system:userPurse:export")
    @Log(title = "用户钱包", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysUserPurseBo bo, HttpServletResponse response) {
        List<SysUserPurseVo> list = sysUserPurseService.queryList(bo);
        ExcelUtil.exportExcel(list, "【请填写功能名称】", SysUserPurseVo.class, response);
    }

    /**
     * 获取用户钱包详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("system:userPurse:query")
    @GetMapping("/{id}")
    public R<SysUserPurseVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(sysUserPurseService.queryById(id));
    }

    /**
     * 新增用户钱包
     */
//    @SaCheckPermission("system:userPurse:add")
    @Log(title = "用户钱包", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysUserPurseBo bo) {
        return toAjax(sysUserPurseService.insertByBo(bo));
    }

    /**
     * 修改用户钱包
     */
//    @SaCheckPermission("system:userPurse:edit")
    @Log(title = "用户钱包", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysUserPurseBo bo) {
        return toAjax(sysUserPurseService.updateByBo(bo));
    }

    /**
     * 删除用户钱包
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("system:userPurse:remove")
    @Log(title = "用户钱包", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(sysUserPurseService.deleteWithValidByIds(List.of(ids), true));
    }

    //    @SaCheckPermission("system:userPurse:queryUserPurse")
    @Log(title = "查询用户钱包", businessType = BusinessType.OTHER)
    @PostMapping("/queryUserPurse")
    public R<SysUserPurseVo> queryUserPurse() {
        return R.ok(sysUserPurseService.queryUserPurse());
    }


    //    @SaCheckPermission("system:userPurse:queryUserPurse")
    @Log(title = "用户记账", businessType = BusinessType.OTHER)
    @GetMapping("/userAccounting")
    public TableDataInfo<SysUserPurseVo> userAccounting(SysUserPurseBo bo, PageQuery pageQuery) {
        return sysUserPurseService.userAccounting(bo, pageQuery);
    }


}
